package com.xyf.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: clms
 * @description:
 * @author: 徐亚飞
 * @create: 2021-07-19 14:54
 **/
public class WebUtil {

        /** 获取request对象 **/
        public static HttpServletRequest getRequest(){
            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            if (requestAttributes == null){
                return null;
            }
            return ((ServletRequestAttributes)requestAttributes).getRequest();
        }
        /** 获取response对象 **/
        public static HttpServletResponse getResponse(){
            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            if (requestAttributes == null){
                return null;
            }
            return ((ServletRequestAttributes)requestAttributes).getResponse();
        }
    }

